home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Button;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.Frame;
- import java.awt.GridLayout;
- import java.awt.Label;
- import java.awt.Window;
-
- public class AppletButton extends Applet implements Runnable {
- int frameNumber = 1;
- String windowClass;
- String buttonText;
- String windowTitle;
- int requestedWidth;
- int requestedHeight;
- Button button;
- Thread windowThread;
- Label label;
- boolean pleaseCreate = false;
-
- public void init() {
- this.windowClass = ((Applet)this).getParameter("WINDOWCLASS");
- if (this.windowClass == null) {
- this.windowClass = "TestWindow";
- }
-
- this.buttonText = ((Applet)this).getParameter("BUTTONTEXT");
- if (this.buttonText == null) {
- this.buttonText = "Click here to bring up a " + this.windowClass;
- }
-
- this.windowTitle = ((Applet)this).getParameter("WINDOWTITLE");
- if (this.windowTitle == null) {
- this.windowTitle = this.windowClass;
- }
-
- String var1 = ((Applet)this).getParameter("WINDOWWIDTH");
- if (var1 != null) {
- try {
- this.requestedWidth = Integer.parseInt(var1);
- } catch (NumberFormatException var4) {
- }
- }
-
- String var2 = ((Applet)this).getParameter("WINDOWHEIGHT");
- if (var2 != null) {
- try {
- this.requestedHeight = Integer.parseInt(var2);
- } catch (NumberFormatException var3) {
- }
- }
-
- ((Container)this).setLayout(new GridLayout(2, 0));
- ((Container)this).add(this.button = new Button(this.buttonText));
- this.button.setFont(new Font("Helvetica", 0, 14));
- ((Container)this).add(this.label = new Label("", 1));
- }
-
- public void start() {
- if (this.windowThread == null) {
- this.windowThread = new Thread(this, "Bringing Up " + this.windowClass);
- this.windowThread.start();
- }
-
- }
-
- public synchronized void run() {
- Object var1 = null;
- Object var2 = null;
- Object var3 = null;
-
- try {
- var8 = Class.forName(this.windowClass);
- } catch (Exception var7) {
- this.label.setText("Can't create window: Couldn't find class " + this.windowClass);
- this.button.disable();
- return;
- }
-
- Class var9 = var8;
-
- for(var10 = var8.getName(); !var10.equals("java.lang.Object") && !var10.equals("java.awt.Frame"); var10 = var9.getName()) {
- var9 = var9.getSuperclass();
- }
-
- if (var10 != null && !var10.equals("java.lang.Object")) {
- if (var10.equals("java.awt.Frame")) {
- while(this.windowThread != null) {
- while(!this.pleaseCreate) {
- try {
- this.wait();
- } catch (InterruptedException var6) {
- }
- }
-
- this.pleaseCreate = false;
- Object var4 = null;
-
- try {
- var11 = (Frame)var8.newInstance();
- } catch (Exception var5) {
- this.label.setText("Couldn't create instance of class " + this.windowClass);
- this.button.disable();
- return;
- }
-
- if (this.frameNumber == 1) {
- var11.setTitle(this.windowTitle);
- } else {
- var11.setTitle(this.windowTitle + ": " + this.frameNumber);
- }
-
- ++this.frameNumber;
- ((Window)var11).pack();
- if (this.requestedWidth > 0 | this.requestedHeight > 0) {
- ((Component)var11).resize(Math.max(this.requestedWidth, ((Component)var11).size().width), Math.max(this.requestedHeight, ((Component)var11).size().height));
- }
-
- ((Window)var11).show();
- this.label.setText("");
- }
- }
-
- } else {
- this.label.setText("Can't create window: " + this.windowClass + " isn't a Frame subclass.");
- this.button.disable();
- }
- }
-
- public synchronized boolean action(Event var1, Object var2) {
- if (var1.target instanceof Button) {
- this.label.setText("Please wait while the window comes up...");
- this.pleaseCreate = true;
- this.notify();
- }
-
- return true;
- }
- }
-